import React from 'react';
import { fetchUserProfile } from '@/util/actions/blogAction';
import BlogList from '@/components/biogComponent/BlogList';
import { cookies } from 'next/headers';
import Link from 'next/link'
import {Button}from 'antd'
const BlogPage = async () => {
  try {
    const cookieStore = cookies();
    const token = cookieStore.get("token");

    if (!token) throw new Error("No token found");

    const userData = await fetchUserProfile(token.value);
console.log("blogpage:"+userData)
  // Ensure userData.blogs is an array
  // const blogsArray = Array.isArray(userData.blogs) ? userData.blogs : [userData];
    return (
      <div>
      <div>
      <Link href="/blog/add">
                    <Button>发表博客</Button>
                </Link>
      </div>
      <div>
        <BlogList blogs={userData} loading={false} />
      </div>

      </div>
    );
  } catch (error) {
    return <div>错误: {error.message}</div>;
  }
};

export default BlogPage;
